Repository navigation
Seed sample data in the Cosmos DB samples' 01-deploy-resources.sh - #56
Merged
Merged
Conversation
The SQL Database, MySQL, PostgreSQL, Blob Storage and Managed Identity samples seed sample activities when 01-deploy-resources.sh creates their data store, while the Cosmos DB for NoSQL and Cosmos DB for MongoDB samples started with an empty list. Their Python and .NET 01-deploy-resources.sh now insert the same nine activities the database samples seed, idempotently, and query them back: - NoSQL: items written through the Cosmos DB REST API with curl, each request signed with the primary master key (openssl), since the Azure CLI has no command for items. A 409 Conflict means the item already exists. - MongoDB: upserts with mongosh that set the fields only on insert. Testing on Azure showed that az cosmosdb create --server-version 7.0 creates a 3.6 account: the Azure CLI sends the version as a ServerVersion property, which the service ignores. PyMongo 4.17 and MongoDB.Driver 3.11, which the MongoDB sample's apps use, and mongosh refuse a 3.6 server, so the sample did not work on Azure. 01-deploy-resources.sh now sets the serverVersion property itself with az rest when the account reports another version, waits for the upgrade, and waits until the MongoDB endpoint accepts connections, which can lag several minutes behind Azure Resource Manager. The Samples CI installs mongosh on the Linux runners for the MongoDB sample; the Windows runner image already ships it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01FvNuJLfY2KkMwaymfFnz7R
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues are recorded for the deployment-time sample-data seeding changes.
No open issues 🎉
What changed in this PR
Aligns the Python and .NET Cosmos DB samples with the other Vacation Planner samples by seeding nine activities during resource deployment, so the app opens with sample data.
Changes:
- Adds repeatable NoSQL and MongoDB seeding that preserves existing activities and queries them back.
- Sets the requested MongoDB server version directly and waits for the endpoint to accept connections.
- Documents host-tool requirements and installs checksum-pinned
mongoshon Linux CI runners.
| File | Description |
|---|---|
samples/web-app-cosmosdb-nosql-api/python/scripts/01-deploy-resources.sh |
Seeds and queries activities using signed REST requests. |
samples/web-app-cosmosdb-nosql-api/python/README.md |
Documents seeding and required curl and openssl tools. |
samples/web-app-cosmosdb-nosql-api/dotnet/scripts/01-deploy-resources.sh |
Adds identical NoSQL seeding for .NET. |
samples/web-app-cosmosdb-nosql-api/dotnet/README.md |
Documents seeding and required host tools. |
samples/web-app-cosmosdb-mongodb-api/python/scripts/01-deploy-resources.sh |
Upgrades MongoDB, waits for connectivity, and seeds activities. |
samples/web-app-cosmosdb-mongodb-api/python/README.md |
Documents seeding, mongosh, and the version workaround. |
samples/web-app-cosmosdb-mongodb-api/dotnet/scripts/01-deploy-resources.sh |
Adds identical MongoDB upgrade and seeding logic for .NET. |
samples/web-app-cosmosdb-mongodb-api/dotnet/README.md |
Documents seeding, mongosh, and the version workaround. |
.github/workflows/run-samples.yml |
Installs checksum-verified mongosh for Linux MongoDB jobs. |
Review effort: Balanced
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
The samples are inconsistent about sample data. The SQL Database, MySQL, PostgreSQL, Blob Storage and Managed Identity samples seed sample activities when
01-deploy-resources.shcreates their data store, so the Vacation Planner opens with a list, while the Cosmos DB for NoSQL and Cosmos DB for MongoDB samples seeded nothing and opened empty. This pull request makes the two Cosmos DB samples, in Python and .NET, seed the same activities as the database samples.Testing the MongoDB sample on Azure showed that it did not work there at all:
az cosmosdb create --kind MongoDB --server-version 7.0creates a 3.6 account, because the Azure CLI sends the version as aServerVersionproperty, which the service ignores (2.91.0, and still on the azure-clidevbranch;az cosmosdb update --server-versionhas the same problem). PyMongo 4.17 and MongoDB.Driver 3.11, which the sample's apps use, refuse a 3.6 server, and so doesmongosh. The script now sets the version itself.The File Storage and in-cluster PostgreSQL samples keep seeding in
05-deploy-app.sh, by design: their data store only exists once the app is deployed (the Azure Files CSI driver creates the share when the claim binds, and the PostgreSQL server runs in the cluster).Fixes SMF-1139
Changes
samples/web-app-cosmosdb-nosql-api/{python,dotnet}/scripts/01-deploy-resources.sh: inserts the nine activities as items{id, username, activity, timestamp}forLOGIN_NAME, the shape the apps read and write, through the Cosmos DB REST API withcurl: the Azure CLI has no command for items. Each request is signed with the primary master key (openssl), as Microsoft's access control page describes. An item id is the MD5 of the user and a fixed name, as in the MySQL sample, so a re-run inserts only the missing items (Cosmos DB answers 409 Conflict for an existing id). The activities are then queried back.samples/web-app-cosmosdb-mongodb-api/{python,dotnet}/scripts/01-deploy-resources.sh:MONGODB_API_VERSION, setsserverVersionwithaz rest(PATCH, the API version the Azure CLI uses) and waits for the upgrade, about a minute.mongoshconnections: on an account that already held data, the endpoint went on serving 3.6 for several minutes after Azure Resource Manager reported 7.0.{_id, username, activity, timestamp}withmongosh, setting the fields only on insert, so a re-run leaves existing documents alone. The filter holds the shard key,username. The activities are then queried back.README.mdfiles: the01-deploy-resources.shrow says what the script seeds and which tool it needs on the host (curlandopenssl, ormongosh), and why the MongoDB script sets the server version itself..github/workflows/run-samples.yml: installsmongosh2.14.1, pinned with its SHA-256, on the Linux runners for the MongoDB sample. The Windows runner image shipsmongosh2.14.1 already.The Python and .NET
01-deploy-resources.shof each sample stay identical.Tests
Each language ran on both targets with the same scripts; the test copies differed only in
PREFIX(andPORT, since 8080 was taken on the host).localstack/localstack-azure:latest, 2026.11.0.dev842):mongoshat once, 9 activities were inserted and listed; the re-runs inserted none.03-run-docker-container.sh: all four apps answer/healthwithokand list the 9 seeded activities.italynorth):03-run-docker-container.sh: all four apps answer/healthwithokand list the 9 seeded activities.bash -npasses on the four scripts. Themongoshrelease's SHA-256 was computed from the downloaded tarball, and the path of the binary in it checked; the step itself runs in this pull request's Samples CI.Related
curlverifies it with its default trust store.🤖 Generated with Claude Code
https://claude.ai/code/session_01FvNuJLfY2KkMwaymfFnz7R